//https://leetcode.cn/problems/path-sum/
//微信 group
class Solution {
public:
    bool hasPathSum(TreeNode* root, int targetSum) {
        if (root == nullptr) return false;
        return dfs(root, 0, targetSum);
    }
    bool dfs(TreeNode* root, int cur_val, int targetSum){
        //叶子节点
        if (root->left == nullptr && root->right == nullptr) {
            if (cur_val + root->val == targetSum) {
                return true;
            }
            return false;
        }
        bool res = false;
        if (root->left != nullptr) {
            res = dfs(root->left, cur_val + root->val, targetSum);
        }
        if(res == true) return res;
        
        if (root->right != nullptr) {
            res = dfs(root->right, cur_val + root->val, targetSum);
        }
        if(res == true) return res;

        return false;

    }
};